<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
 
<div style="margin:20px 0;"></div>
<div class="easyui-panel" >
	<div style="padding:10px 60px 20px 60px">
    <form id="areaForm"  name="areaForm" method="post" >
    	<input type="hidden" id="area_uuid" name="area_uuid" value="${appAreaCdEntity.area_uuid}"/>
    	<input type="hidden" id="sup_area_cd" name="sup_area_cd" value="${appAreaCdEntity.sup_area_cd}"/>
    	<table cellpadding="5" style="width:100%">
    		<tr>
    			<td>地区代码:</td>
    			<td><input class="easyui-textbox" type="text" id="area_cd" name="area_cd" data-options="required:true,validType:['checkAreaCd']" value="${appAreaCdEntity.area_cd }"></input></td>    	     			
    		</tr>
    		<tr>
    			<td>地区中文名:</td>
    			<td><input class="easyui-textbox" type="text"  name="area_cn_nm" data-options="required:true,validType:['length[0,20]']" value="${appAreaCdEntity.area_cn_nm}"></input></td>    		     			
    		</tr>
    		<tr>
    			<td>地区英文名:</td>
    			<td><input class="easyui-textbox" type="text"  name="area_en_nm" data-options="validType:['checkEnNm']" value="${appAreaCdEntity.area_en_nm}"></input></td>    		     			
    		</tr>   
    		<tr>
    			<td>区号:</td>
    			<td><input class="easyui-textbox" type="text"  name="zipcd" data-options="validType:['checkzipcd']" value="${appAreaCdEntity.zipcd}"></input></td>    		     			
    		</tr>
    		<tr>
    			<td>上级地区代码:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="cdAndName" value="${cdAndName}"/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctBtn">选择</a></td>    			   		     			
    		</tr>
    		<tr>
    			<td>4位地区代码:</td>
    			<td><input class="easyui-textbox" type="text"  name="bank_area_cd" data-options="validType:['checkbankareacd']" value="${appAreaCdEntity.bank_area_cd}"></input></td>    		     			
    		</tr>
    		<tr>
    			<td>级别:</td>
    			<td><input class="easyui-textbox" type="text"  name="level_no" data-options="required:true,validType:['checklevelno']" value="${appAreaCdEntity.level_no}"></input></td>    		     			
    		</tr> 		    		 
    	</table>
    
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-save" id="saveBtn">保存</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
	    </div>
    </form>
    </div>
</div>
<script>
$(document).ready(function() {	
	$.extend($.fn.textbox.defaults.rules, {           
		checkAreaCd: {     
            validator: function(value){               
                 var reg = new RegExp("^[0-9]{6}$"); 
                 return reg.test(value);  
            },     
            message: '地区代码需为6位数字'     
        },
        checkEnNm: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z]{0,30}$"); 
                 return reg.test(value);  
            },     
            message: '地区英文名需为0-30个字母'     
        },
        checkzipcd: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z0-9]{6}$"); 
                 return reg.test(value);  
            },     
            message: '区号需为6位数字或字母'     
        },
        checkbankareacd: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z0-9]{4}$"); 
                 return reg.test(value);  
            },     
            message: '4位地区代码需为4位数字或字母'     
        },
        checklevelno: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z0-9]{1}$"); 
                 return reg.test(value);  
            },     
            message: '级别需为1位数字或字母'     
        }
	});
	
	checkAreaCd();
	/*选择按钮*/
	$("#selelctBtn").click(function(){
		showAreaTree(selected);
	});
	/*确定按钮回调*/
	function selected(nodes){
		if(nodes && nodes.length > 0){
			$("#sup_area_cd").val(nodes[0].ID);
			$("#cdAndName").textbox("setValue", nodes[0].NAME);
		}
	}
	$("#saveBtn").click(function(){			
		if($("#areaForm").form("validate")){				
			var options ={   
		            url:'<c:url value="/areacd/checkAreaCd.do"/>',   
		            type:'post',                    
		            success:function(data){
		            	  var result=data;
						  if("success"==result){					  
							  //表单提交的方法、比如ajax提交
					    	  $("#areaForm").attr("action","../areacd/saveAreaCd.do?");
					    	  document.getElementById("areaForm").submit();  						  
						  }else{
							  $.jpmessage.info('地区代码不能重复!');
						  }
		            }   
		         };
			$("#areaForm").ajaxSubmit(options); 
		}
		
	});
	
});

function checkAreaCd(){
	var area_uuid=$("#area_uuid").val();
	if(area_uuid!=""){
		$("#area_cd").textbox('textbox').attr('readonly',true);
	}
}
 
	
</script>